% ************************************************************************* %
% ********                         HYTEX 7.1                       ******** %
% ********                       By Rob Hyndman                    ******** %
% ************************************************************************* %
%                                                                           %
% This style file contains some additions to the LaTeX document styles.     %
% It is intended to be used with one of the common LaTeX classes such as    %
% article, report, book or letter.                                          %
%                                                                           %
% Any suggestions, bugs, complaints or donations should be addressed to     %
%         Rob J. Hyndman                                                    %
%         Department of Econometrics and Business Statistics                %
%         Monash University,                                                %
%         Clayton, Victoria, 3800,                                          %
%         AUSTRALIA                                                         %
%         (Rob.Hyndman@buseco.monash.edu.au)                                %
%                                                                           %
% ************************************************************************* %

\typeout{HyTeX Version 7.2    <8 May 2008>}

\DeclareRobustCommand{\HyTeX}{H\kern-.085em%
        {\sbox\z@ T%
         \vbox to\ht0{\vss\hbox{$\m@th$%
                            \csname S@\f@size\endcsname
                            \fontsize\sf@size\z@
                            \math@fontsfalse\selectfont
                            Y}}%
        }%
        \kern-.27em%
        \TeX}

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{hytex}
            [2008/04/08 v7.2]
\RequirePackage{setspace}
\RequirePackage{parskip}
\RequirePackage{amsmath}

% ABBREVIATIONS -------------------------------------------------------------

\def\biz{\begin{itemize}}
\def\eiz{\end{itemize}}
\def\ben{\begin{enumerate}}
\def\een{\end{enumerate}}
\def\bt{\begin{center}\begin{tabular}}
\def\et{\end{tabular}\end{center}}

% BLANK PAGE ----------------------------------------------------------------

\def\blankpage{\newpage\null\thispagestyle{empty}\newpage}

% BOXED PARAGRAPHS ----------------------------------------------------------

\def\boxpar#1#2{\begin{center}\begin{singlespace}
                \vskip -\parskip
                \fbox{\parbox{#1}{#2}}
                \end{singlespace}\end{center}}

\def\eqnbox#1{\fbox{$\displaystyle #1$}}
\def\boxeqn#1{\vspace{0.2cm}\par\hbox{\fbox{\hbox to 0.99\textwidth{
                  \parbox{0.98\textwidth}{#1}\hss}}\hss}\noindent}

%% Addition: Shadebox behaves like parbox except shaded.
%% \usecolor must be issued first.

\newcommand{\shadebox}[3][.9]{\fcolorbox[gray]{0}{#1}{\parbox{#2}{#3}}}

% CHAPTER HEADS -------------------------------------------------------------

% Define the command \mychapter{<head1>}{<head2>}.    <head1>
% is the text to put in the chapter head if there is a
% chapter number; <head2>, if not.

\def\@chapapp{Chapter}
\def\chapapp{\@chapapp}

\def\mychapter#1#2{
   \def\@chaphead##1{#1}
   \def\@schaphead##1{#2}
}

\def\@makechapterhead#1{ \vspace*{\chaptopsep} { \parindent 0pt \raggedright
 \ifnum \c@secnumdepth >\m@ne \@chaphead{#1} \else \@schaphead{#1} \fi
 \par \nobreak \vskip \chapaftersep } }
\def\@makeschapterhead#1{ \vspace*{\chaptopsep} { \parindent 0pt \raggedright
 \@schaphead{#1}\par
 \nobreak \vskip \chapaftersep } }

% \chaptopsep is the space between the top of the text page and the
% chapter head.     \chapaftersep is the space between the chapter
% head and the text.
\newlength{\chaptopsep}
\setlength{\chaptopsep}{1.8cm}
\newlength{\chapaftersep}
\setlength{\chapaftersep}{1.4cm}

%  Boxed chapter number
\def\boxchapter{
\@ifundefined{chapter}{}{\renewcommand{\thechapter}{\arabic{chapter}}
   \mychapter{\huge\sf \raisebox{-0.cm}{\fbox{\thechapter}}~~
   \raisebox{1.02cm}{\parbox[t]{13.5cm}{\flushleft ##1}}\\ \nobreak \vskip
   0.2cm \rule{\textwidth}{0.1cm }}
            {\huge\sf ##1\\ \nobreak \vskip 0.2cm \rule{\textwidth}{0.1cm}}
   \def\@chapapp{}%\hspace*{-0.1cm}}
}}

% Make chapter headings in sans serif font
\def\chapfont{\sf}
\def\sfchapter{
\@ifundefined{chapter}{}{\mychapter{\begin{singlespace}\flushright
   \huge\chapfont\chapapp\ \thechapter\\[20pt]
   \flushright\Huge\chapfont ##1\\ \nobreak \vskip -0.5cm
   \rule{\textwidth}{0.1cm}\end{singlespace}}}
  {\begin{singlespace}\flushright\Huge\chapfont ##1\\ \nobreak \vskip
  -0.5cm \rule{\textwidth}{0.1cm}\end{singlespace}
}}
\def\sfbchapter{\def\chapfont{\sfb}\sfchapter}


% COLUMNS -------------------------------------------------------------------
% For use with the multicol package

\def\newcolumn{\columnbreak}

% DATE AND TIME -------------------------------------------------------------

\def\Date{\number\day}
\def\Month{\ifcase\month\or
 January\or February\or March\or April\or May\or June\or
 July\or August\or September\or October\or November\or December\fi}
\def\Mon{\ifcase\month\or
 Jan\or Feb\or Mar\or Apr\or May\or Jun\or
  Jul\or Aug\or Sep\or Oct\or Nov\or Dec\fi}
\def\Year{\number\year}
\def\Yr{\tempy=\year\advance\tempy by -1900
         \ifnum \tempy>99 \advance\tempy -100 \fi\twodigits\tempy} % corrects for 2000

\newcount\dow                             % Gets day of the week
\newcount\leap                          % Leap year fingaler
\newcount\tempx                                % Temp register
\newcount\tempy                                % Another temp register

% Day of week -- written by Martin Minow of DEC (minow%bolt.dec@decwrl.dec.com).
% Calculates day of the week, return "Sunday", etc.
\def\Dow{%
%                leap = year + (month - 14)/12;
  \leap=\month \advance\leap by -14 \divide\leap by 12
  \advance\leap by \year
%                dow = (13 * (month + 10 - (month + 10)/13*12) - 1)/5
  \dow=\month \advance\dow by 10
  \tempy=\dow \divide\tempy by 13 \multiply\tempy by 12
  \advance\dow by -\tempy \multiply\dow by 13 \advance\dow by -1 \divide\dow by 5
%                dow += day + 77 + 5 * (leap % 100)/4
  \advance\dow by \day \advance\dow by 77
  \tempx=\leap \tempy=\tempx \divide\tempy by 100 \multiply\tempy by 100 \advance\tempx by -\tempy
  \multiply\tempx by 5 \divide\tempx by 4 \advance\dow by \tempx
%                dow += leap / 400
  \tempx=\leap \divide\tempx by 400 \advance\dow by \tempx
%                dow -= leap / 100 * 2;
%                dow = (dow % 7)
  \tempx=\leap \divide\tempx by 100 \multiply\tempx by 2 \advance\dow by -\tempx
  \tempx=\dow \divide\tempx by 7 \multiply\tempx by 7 \advance\dow by -\tempx
  \ifcase\dow Sunday\or Monday\or Tuesday\or Wednesday\or
        Thursday\or Friday\or Saturday\fi
}

\renewcommand{\today}[1][0]{\tempx=#1
        \ifcase\tempx{\Date\ \Month\ \Year}\or            % 21 July 1997
                 {\Date\ \Mon\ \Yr}\or                    % 21 Jul 97
                 {\Dow, \Date\ \Month\ \Year}\or      % Wednesday, 21 July 1997
                 {\twodigits{\Date}.\twodigits{\number\month}.\Yr}% 21.07.97
                 \fi}

%\def\today{\Date\ \Month\ \Year} % Australian formatted date.    E.g. 21 July 1997

% Time stamp
\def\clock{\tempx=\time \divide\tempx 60
  \tempy=-\tempx \multiply\tempy 60 \advance\tempy \time
  \ifnum \tempx>12 \advance\tempx -12 \fi
   \number\tempx.\twodigits\tempy\ampm\time}
\def\ampm#1{\ifnum #1< 720 am\else pm\fi}
\def\twodigits#1{\ifnum #1<10 0\fi \number#1}


% SPACING ------------------------------------------------------------

%Additions by RJH (for backwards compatibility):

\def\doublespaced{\doublespacing}
\def\setspacing#1{\linespread{#1}}
\def\spacing#1{\linespread{#1}}

\newenvironment{newspacing}[1]{%
  \par
  \begingroup
    \linespread {#1}%
}{%
  \restore@spacing
}


% DRAFTS -------------------------------------------------------------------

\def\draft{\usepackage{color}\date{\clock, \today}\rfoot{\color{red}\small\sf DRAFT: \clock, \today}}

% FIGURES -----------------------------------------------------------------

\newcommand{\graph}[4][tb]{\begin{figure}[#1]\centering
        \includegraphics[#2]{#3}
        {\small\textbf{\caption{\it #4}\label{#3}}}
        \end{figure}}

% FONTS --------------------------------------------------------------------

\DeclareOldFontCommand{\sfb}{\normalfont\sffamily\bfseries}{\@nomath\sfb}
\def\textsfb#1{\textsf{\textbf{#1}}}

%Postscript fonts
\def\timesroman{\renewcommand{\rmdefault}{ptm}}
\def\bookman{\renewcommand{\rmdefault}{pbk}}
\def\palatino{\renewcommand{\rmdefault}{ppl}}
\def\newcentury{\renewcommand{\rmdefault}{pnc}}
\def\avantgarde{\renewcommand{\sfdefault}{pag}}
\def\helvetica{\renewcommand{\sfdefault}{phv}}
\def\courier{\renewcommand{\ttdefault}{pcr}}

% HEADERS AND FOOTERS -----------------------------------------------------

% Based on an old version of fancyhdr.sty

\def\prehead{}\def\prefoot{}
\def\posthead{}\def\postfoot{}

\def\headstyle#1{\def\headstyl{#1}}
\headstyle{\sl} % Sets style of all headers
                % Can be overwritten within \lhead, \rhead, etc.
\def\footstyle#1{\def\footstyl{#1}}
\footstyle{\sl} % Sets style of all footers
                % Can be overwritten within \lfoot, \rfoot, etc.

% Upper and lowercase
\def\uppercasehead{\def\case##1{\uppercase{##1}}}
\def\lowercasehead{\def\case##1{##1}}
\lowercasehead

\def\lhead#1{\gdef\@lhead{\prehead\headstyl{#1}}\gdef\@erhead{\headstyl{#1}\posthead}}
\def\lfoot#1{\gdef\@lfoot{\prefoot\footstyl{#1}}\gdef\@erfoot{\footstyl{#1}\postfoot}}
\def\chead#1{\gdef\@chead{\headstyl{#1}}\gdef\@echead{\headstyl{#1}}}
\def\cfoot#1{\gdef\@cfoot{\footstyl{#1}}\gdef\@ecfoot{\footstyl{#1}}}
\def\rhead#1{\gdef\@rhead{\headstyl{#1}\posthead}\gdef\@elhead{\prehead\headstyl{#1}}}
\def\rfoot#1{\gdef\@rfoot{\footstyl{#1}\postfoot}\gdef\@elfoot{\prefoot\footstyl{#1}}}
\def\elhead#1{\gdef\@elhead{\prehead\headstyl{#1}}}
\def\elfoot#1{\gdef\@elfoot{\prefoot\footstyl{#1}}}
\def\echead#1{\gdef\@echead{\headstyl{#1}}}
\def\ecfoot#1{\gdef\@ecfoot{\footstyl{#1}}}
\def\erhead#1{\gdef\@erhead{\headstyl{#1}\posthead}}
\def\erfoot#1{\gdef\@erfoot{\footstyl{#1}\postfoot}}

\def\@lhead{\prehead}\def\@lfoot{\prefoot}
\def\@chead{}\def\@cfoot{}
\def\@rhead{\posthead}\def\@rfoot{\postfoot}
\def\@elhead{\prehead}\def\@elfoot{\prefoot}
\def\@echead{}\def\@ecfoot{}
\def\@erhead{\posthead}\def\@erfoot{\postfoot}

\def\@threepart#1#2#3{\rlap{#1} \hfil {#2} \hfil \llap{#3}}

\def\ps@threepartheadings{
    \let\@mkboth\markboth
    \def\@oddhead{\@threepart{\@lhead}{\@chead}{\@rhead}}
    \def\@oddfoot{\@threepart{\@lfoot}{\@cfoot}{\@rfoot}}
    \if@twoside
        \def\@evenhead{\@threepart{\@elhead}{\@echead}{\@erhead}}
        \def\@evenfoot{\@threepart{\@elfoot}{\@ecfoot}{\@erfoot}}
        \@ifundefined{chapter}{
        \def\sectionmark##1{\markboth {\case{\ifnum \c@secnumdepth >\z@
            \thesection\hskip 1em\relax \fi ##1}}{}}
        \def\subsectionmark##1{\markright {\case{\ifnum \c@secnumdepth >\@ne
            \thesubsection\hskip 1em\relax \fi ##1}}}}{
        \def\chaptermark##1{\markboth {\case{\ifnum \c@secnumdepth >\m@ne
            \chapapp\ \thechapter. \ \fi ##1}}{}}
        \def\sectionmark##1{\markright {\case{\ifnum \c@secnumdepth >\z@
             \thesection. \ \fi ##1}}}}
    \else
        \def\@evenhead{\@threepart{\@lhead}{\@chead}{\@rhead}}
        \def\@evenfoot{\@threepart{\@lfoot}{\@cfoot}{\@rfoot}}
        \@ifundefined{chapter}{
        \def\sectionmark##1{\markright {\case{\ifnum \c@secnumdepth >\z@
            \thesection\hskip 1em\relax \fi ##1}}}}{
        \def\chaptermark##1{\markright {\case{\ifnum
            \c@secnumdepth >\m@ne \chapapp\ \thechapter. \ \fi ##1}}}}
    \fi
}

% Underlined and boxed headers and footers

% Define \underhead to put a rule under the headers.  The space between
% the text and the rule is \underheadsep.
% \nounderhead has been removed.

\newlength{\overfootsep}\setlength{\overfootsep}{2ex}
\newlength{\underheadsep}\setlength{\underheadsep}{1ex}
\newlength{\overfootwidth}\setlength{\overfootwidth}{0.01cm}
\newlength{\underheadwidth}\setlength{\underheadwidth}{0.01cm}

\def\underhead{\addtolength{\headheight}{\underheadsep}
        \def\prehead{\raisebox{-\underheadsep}[0cm][0cm]{%
                \hbox to 0cm{\rule{\textwidth}{\underheadwidth}\hss}}}}

\def\overfoot{\addtolength{\textheight}{-\overfootsep}
        \def\prefoot{\raisebox{\overfootsep}[0cm][0cm]{%
                \hbox to 0cm{\rule{\textwidth}{\overfootwidth}\hss}}}}

\def\boxhead{\addtolength{\headheight}{\underheadsep}
        \def\posthead{\hspace*{1ex}}
        \def\prehead{\raisebox{0cm}[0cm][0cm]{%
                \hbox to 0cm{\fbox{\hbox to 0.984\textwidth{
                                        \phantom{Ay}\hfil}}\hss}}~}}

\def\boxfoot{\addtolength{\textheight}{-\overfootsep}
        \def\postfoot{\hspace*{1ex}}
        \def\prefoot{\rule{0cm}{2\overfootsep}\raisebox{0.0cm}[0cm][0cm]{%
                \hbox to 0cm{\fbox{\hbox to 0.984\textwidth{
                                        \phantom{Ay}\hfil}}\hss}}~}}

%% Note \usecolor must be used before either \shadehead or \shadefoot

\newcommand\shadehead[1][.9]{\addtolength{\headheight}{\underheadsep}
        \def\posthead{~}
        \def\prehead{\raisebox{0cm}[0cm][0cm]{%
             \hbox to 0cm{\colorbox[gray]{#1}{\parbox{0.986\textwidth}
                {\rule{0cm}{0.5cm}}}\hss}}~}}

\newcommand\shadefoot[1][.9]{\addtolength{\textheight}{-\overfootsep}
        \def\postfoot{~}
        \def\prefoot{\raisebox{0cm}[0cm][0cm]{%
            \hbox to 0cm{\colorbox[gray]{#1}{\parbox{0.986\textwidth}
                {\rule{0cm}{0.5cm}}}\hss}}~}}

\newcommand\shadeboxhead[1][.9]{\addtolength{\headheight}{\underheadsep}
        \def\posthead{~}
        \def\prehead{\raisebox{0cm}[0cm][0cm]{%
             \hbox to 0cm{\fcolorbox[gray]{0}{#1}{\parbox{0.986\textwidth}
                {\rule{0cm}{0.5cm}}}\hss}}~}}

\newcommand\shadeboxfoot[1][.9]{\addtolength{\textheight}{-\overfootsep}
        \def\postfoot{~}
        \def\prefoot{\raisebox{0cm}[0cm][0cm]{%
            \hbox to 0cm{\fcolorbox[gray]{0}{#1}{\parbox{0.986\textwidth}
                {\rule{0cm}{0.5cm}}}\hss}}~}}

\newcommand\normalhead{\def\posthead{}\def\prehead{}}
\newcommand\normalfoot{\def\postfoot{}\def\prefoot{}}


\def\ps@empty{\let\@mkboth\@gobbletwo\def\@oddhead{}\def\@oddfoot{}%
\def\@evenhead{}\def\@evenfoot{}}

\def\ps@plain{\let\@mkboth\@gobbletwo
     \def\@oddhead{}\def\@oddfoot{\footstyl\hfil\prepageno\thepage
     \hfil}\def\@evenhead{}\let\@evenfoot\@oddfoot}

\def\ps@footers{\let\@mkboth\@gobbletwo
    \def\@oddhead{\@threepart{}{}{}}
    \def\@oddfoot{\@threepart{\@lfoot}{\@cfoot}{\@rfoot}}
    \def\@evenhead{\@threepart{}{}{}}
    \def\@evenfoot{\@threepart{\@lfoot}{\@cfoot}{\@rfoot}}
}

\def\prepageno{\null}


% LISTS

\newenvironment{labeling}[2][\bf]
  {\def\sc@septext{}
   \list{}{\settowidth{\labelwidth}{\hbox{#1{#2}}}%
    \def\labelfont{#1}%
     \leftmargin\labelwidth \advance\leftmargin by \labelsep
     \let\makelabel\labelinglabel}}
  {\endlist}

\newcommand\labelinglabel[1]{\labelfont{#1}\hfil\sc@septext}


% MARGINAL NOTES

\def\mnote#1{\marginpar{\spacing{1}\footnotesize\raggedright\hspace{0pt}#1}}


% MATHEMATICAL SYMBOLS ----------------------------------------------------

%\renewcommand*{~}{\relax\ifmmode\sim\else\nobreakspace{}\fi}
%\let\STATEXequal=\=
%\renewcommand*{\=}{\relax\ifmmode\expandafter\bar\else\expandafter\STATEXequal\fi}
%\let\STATEXhat=\^
%\renewcommand*{\^}{\relax\ifmmode\expandafter\widehat\else\expandafter\STATEXhat\fi}
%\let\STATEXtilde=\~
%\renewcommand*{\~}{\relax\ifmmode\expandafter\widetilde\else\expandafter\STATEXtilde\fi}

\def\invstackrel#1#2{\mathord{\mathop{#1}\limits_{#2}}}

\newcommand*{\iid}{\stackrel{\text{iid}}{~}}
\def\dist{\stackrel{d}{=}}
\def\smallfrac#1#2{{\textstyle\frac{#1}{#2}}}
\def\bddots{\mathinner{\mkern1mu\raise1pt\hbox{.}\mkern2mu
        \raise4pt\hbox{.}\mkern2mu\raise7pt\vbox{\kern7pt\hbox{.}}\mkern1mu}}

% Statistical functions

\def\statfn#1{\mathchoice{\mbox{\textnormal{#1}}}{\mbox{\textnormal{#1}}}
{\mbox{\textnormal{\scriptsize #1}}}{\mbox{\textnormal{\scriptsize
#1}}}}

\def\cov{\statfn{Cov}}
\def\corr{\statfn{Corr}}
\def\var{\statfn{Var}}
\def\E{\statfn{E}}
\def\Pr{\statfn{Pr}}
\def\given{\mathop{|}}

\def\sfE{\def\cov{\statfn{\textsf{Cov}}}
         \def\corr{\statfn{\textsf{Corr}}}
         \def\var{\statfn{\textsf{Var}}}
         \def\E{\statfn{\textsf{E}}}
         \def\Pr{\statfn{\textsf{Pr}}}}

\DeclareMathOperator{\logit}{logit}
\DeclareMathOperator{\diag}{diag}


% PAGE NUMBERS ---------------------------------------------------------------

\def\sfpage{\def\prepageno{\sf}}
\def\sfbpage{\def\prepageno{\sfb}}

% PAGE SIZE ------------------------------------------------------------------

\newlength{\sidemargin}
\def\setsidemargin#1{\setlength{\sidemargin}{#1}
   \setlength{\textwidth}{\paperwidth}\addtolength{\textwidth}{-2\sidemargin}
   \setlength{\oddsidemargin}{-2.5cm}\addtolength{\oddsidemargin}{\sidemargin}
   \setlength{\evensidemargin}{\oddsidemargin}}

\def\setbinding#1{\advance\oddsidemargin by #1\advance\evensidemargin by -#1}

\def\setmarginparleft#1{\setlength{\marginparwidth}{#1}
        \addtolength{\textwidth}{-\marginparwidth}
        \addtolength{\oddsidemargin}{\marginparwidth}
        \setlength{\evensidemargin}{\oddsidemargin}\reversemarginpar}

\def\setmarginparright#1{\setlength{\marginparwidth}{#1}
        \addtolength{\textwidth}{-\marginparwidth}}

\def\letterpage{\setlength{\paperheight}{11in}\setlength{\paperwidth}{8.5in}
\setlength{\textheight}{8.5in}}

\def\a4page{\setlength{\paperheight}{297mm}\setlength{\paperwidth}{210mm}
\setlength{\textheight}{235mm}}

\newlength{\junkh}

\def\rotatepage{\setlength{\junkh}{\paperheight}\setlength{\paperheight}{\paperwidth}
\setlength{\paperwidth}{\junkh}\setlength{\junkh}{\textheight}
\setlength{\textheight}{\textwidth}\setlength{\textwidth}{\junkh}\special{landscape}}


% QUOTES ---------------------------------------------------------------------

\def\smallquote{\renewenvironment{quote}
   {\begin{list}{}{\rightmargin\leftmargin\topsep=-0.5\parskip}%
     \small\item\relax}
   {\end{list}}}

\def\hfilll{\\\null\hfill}% Mimics \flushright but with less space.
\newcommand*{\atright}[1]{{%
  \unskip\nobreak\hfill\penalty50
  \hskip2em\hbox{}\nobreak\hfill#1
  \parfillskip=0pt\finalhyphendemerits=0\par}}

% SECTION HEADS --------------------------------------------------------------

% Define the command \mysection{<sec>}{<style>}{<prefix>}.
% <sec> is the section level--section, subsection, etc.     <style>
% is the style in which the section head is to be set; e.g.,
% \large\bf.  <prefix> is what precedes the head text, usually
% \the<sec> followed by some punctuation.

\def\@startsection#1#2#3#4#5#6{\if@noskipsec \leavevmode \fi
   \par \@tempskipa #4\relax
   \@afterindenttrue
   \ifdim \@tempskipa <\z@ \@tempskipa -\@tempskipa \@afterindentfalse\fi
   \if@nobreak \everypar{}\else
     \addpenalty{\@secpenalty}\addvspace{\@tempskipa}\fi \@ifstar
     {\@ssect{#3}{#4}{#5}{#1}}{\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}

\def\@sect#1#2#3#4#5#6[#7]#8{\ifnum #2>\c@secnumdepth
     \def\@svsec{}\else
     \refstepcounter{#1}
     \edef\@svsec{\expandafter\relax\csname @pre#1\endcsname}\fi
     \@tempskipa #5\relax
      \ifdim \@tempskipa>\z@
        \begingroup \expandafter\relax\csname @#1style\endcsname\relax
            \@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty \@M
            #8\par}
        \endgroup
        \csname #1mark\endcsname{#7}\addcontentsline
         {toc}{#1}{\ifnum #2>\c@secnumdepth \else
                      \protect\numberline{\csname the#1\endcsname}\fi
                    #7}\else
        \def\@svsechd{%
            \expandafter\relax\csname @#1style\endcsname\relax
            \hskip #3\@svsec #8\csname #1mark\endcsname
                      {#7}\addcontentsline
                             {toc}{#1}{\ifnum #2>\c@secnumdepth \else
                             \protect\numberline{\csname the#1\endcsname}\fi
                        #7}}\fi
     \@xsect{#5}}


\def\@ssect#1#2#3#4#5{\@tempskipa #3\relax
   \ifdim \@tempskipa>\z@
     \begingroup \expandafter\relax\csname @#4style\endcsname\relax
     \@hangfrom{\hskip #1}{\interlinepenalty \@M #5\par}\endgroup
   \else \def\@svsechd{#4\hskip #1\relax #5}\fi
    \@xsect{#3}}

\newlength{\presectionskip}\setlength{\presectionskip}{3.5ex plus 1ex}
\newlength{\presubsectionskip}\setlength{\presubsectionskip}{3.25ex plus 1ex}
\newlength{\presubsubsectionskip}\setlength{\presubsubsectionskip}{3.25ex plus 1ex}
\newlength{\postsectionskip}\setlength{\postsectionskip}{2.3ex plus .2ex}
\newlength{\postsubsectionskip}\setlength{\postsubsectionskip}{1.5ex plus .1ex}
\newlength{\postsubsubsectionskip}\setlength{\postsubsubsectionskip}{1.5ex plus .1ex}

\@ifundefined{section}{}{%
    \renewcommand\section{\@startsection {section}{1}{\z@}%
        {-\presectionskip}{\postsectionskip}{\normalfont\Large\bfseries}}%
    \renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
        {-\presubsectionskip}{\postsubsectionskip}{\normalfont\large\bfseries}}
    \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
        {-\presubsubsectionskip}{\postsubsubsectionskip}{\normalfont\normalsize\bfseries}}}


\def\mysection#1#2#3{
     \expandafter\def\csname @#1style\endcsname{#2}
     \expandafter\def\csname @pre#1\endcsname{#3}
}
\def\sfsection{
\mysection{section}{\Large\sf}{\thesection~~}
\mysection{subsection}{\large\sf}{\thesubsection~~}
\mysection{subsubsection}{\normalsize\sf}{\thesubsubsection~~}}

\def\sfbsection{
\mysection{section}{\Large\sfb}{\thesection~~}
\mysection{subsection}{\large\sfb}{\thesubsection~~}
\mysection{subsubsection}{\normalsize\sfb}{\thesubsubsection~~}}

\def\msection#1{\addtocounter{section}{1}\section*{\hskip -\marginparwidth\hskip -\marginparsep
\settoheight{\junkh}{\@sectionstyle T}
\vbox to \junkh{\parbox[t]{\marginparwidth}{\raggedleft\thesection~#1}\vss}}
\vspace*{-\postsectionskip}\vspace*{-\parskip}\vspace*{-\baselineskip}\par}

\def\msectionstar#1{\addtocounter{section}{1}\section*{\hskip -\marginparwidth\hskip -\marginparsep
\settoheight{\junkh}{\@sectionstyle T}
\vbox to \junkh{\parbox[t]{\marginparwidth}{\raggedleft#1}\vss}}
\vspace*{-\postsectionskip}\vspace*{-\parskip}\vspace*{-\baselineskip}\par}


\def\msubsection#1{\addtocounter{subsection}{1}\subsection*{\hskip -\marginparwidth\hskip -\marginparsep
\settoheight{\junkh}{\@subsectionstyle T}
\vbox to \junkh{\parbox[t]{\marginparwidth}{\raggedleft \thesubsection~#1}\vss}}
\vspace*{-\parskip}\vspace*{-\postsubsectionskip}\vspace*{-\baselineskip}\par}


% TABLES OF CONTENTS ---------------------------------------------------------

% Define \tighttoc to alter table of contents entry so that
% sections are treated like subsections, subsubsections, etc.
\def\tighttoc
    {
        \dimen100 = \parskip
        \setlength{\parskip}{0pt}
        \tableofcontents
        \setlength{\parskip}{\dimen100}
    }

%% Make toc with section heading instead of chapter.
\def\sectiontoc{\def\tableofcontents{\section*{\contentsname%
        \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
        \@starttoc{toc}}}

\def\justtoc{\@starttoc{toc}}

\def\tighttoccols
    {
        %\def\l@section{\@dottedtocline{1}{0em}{1.4em}}
        \dimen100 = \parskip
        \setlength{\parskip}{0pt}
        \chapter*{\contentsname
        \@mkboth{%
             \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
        \begin{multicols}{2}%
        \@starttoc{toc}%
        \end{multicols}%
        \setlength{\parskip}{\dimen100}
    }

%% Only alteration to dottedtocline is font for page number
\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalcolor #5}%
     \par}%
  \fi}

\def\noboldtoc{\def\l@section{\@dottedtocline{1}{0em}{1.4em}}}


% TABS -----------------------------------------------------------------

\newlength{\tabwidth}\setlength{\tabwidth}{1cm}
\def\tab#1{\hspace*{#1\tabwidth}}

% TABLES ---------------------------------------------------------------

% Bold lines in tables
\def\bhline#1{\noalign{\ifnum0=`}\fi\hrule \@height #1\arrayrulewidth
        \futurelet \@tempa\@xhline}
\def\bvline#1{\vrule \@width #1\arrayrulewidth}
\let\mc\multicolumn

% TITLES ---------------------------------------------------------------------

\def\hytextitle{\par
 \begingroup
   \def\thefootnote{\fnsymbol{footnote}}%
   \def\@makefnmark{\hbox
        to\z@{$\m@th^{\@thefnmark}$\hss}}%
   \if@twocolumn
     \twocolumn[\@hytextitle]%
     \else \newpage
     \global\@topnum\z@
     \@hytextitle \fi\thispagestyle{plain}\@thanks
 \endgroup
 \setcounter{footnote}{0}%
% \let\hytextitle\relax
% \let\@hytextitle\relax
 \gdef\@thanks{}\let\thanks\relax}

\def\@hytextitle{\newpage
  {\raggedright\LARGE\titlefont{\@title}\par}%
  \vskip 1.2em
  \hbox to \hsize{\authorfont{\large \begin{tabular}{@{}l@{}}\@author\end{tabular}
                 \hfil\normalsize\begin{tabular}{@{}l@{}}\@date\end{tabular}}}
  \par
  \hbox to \hsize{\hrulefill}
  \par
  \vskip 1.0em}

\def\boxtitle{\def\@hytextitle{\newpage
  \fbox{\parbox{0.98\hsize}{{\raggedright\LARGE\titlefont \@title \par}%
  \vskip 1.5em
  \hbox to \hsize{\textsf{\large \@author \hfil\normalsize\@date}}
  \par}}\vskip 1.0em}}

\def\titlehead{\@ifundefined{@title}\else\lhead{\@title}}
\def\titlefont{\textsfb}
\def\boldtitle{\def\titlefont{\textsfb}}
\def\authorfont{\textsf}

\newenvironment{hytexboxtitle}
        {\newlength{\titlewidth}\setlength{\titlewidth}{\textwidth}
         \addtolength{\titlewidth}{-1cm}\addtolength{\titlewidth}{-2pt}
         \begin{tabular}{|@{\hspace*{0.5cm}}p{\titlewidth}@{\hspace*{0.5cm}}|}
         \hline\begin{minipage}{\titlewidth}\parskip=2.5ex\sf\hytextitle}
        {\end{minipage}\\\\\hline\end{tabular}\vskip 1.0cm}

\newenvironment{hytextitlepage}
        {\begin{hytexboxtitle}}
        {\end{hytexboxtitle}\newpage}


% TODO -------------------------------------------------------------------

\def\todo#1{{\centering\fbox{\parbox{0.8\textwidth}{\sf #1}}}\marginpar{\colorbox{yellow}{\sf\tiny TO DO}}}
\def\inlinetodo#1{\fbox{\sf #1}\marginpar{\colorbox{yellow}{\sf\tiny TO DO}}}

% TWOUP -----------------------------------------------------------------
%% Need 2up.sty

\def\twoup{\usepackage{2up}\special{landscape}
\target{760}{\paperheight}{\paperwidth}\source{\magstep0}{\paperwidth}{\paperheight}
\ifpdf{\setlength{\pdfpagewidth}{390.8mm}\setlength{\pdfpageheight}{276.3mm}
    \setlength{\pdfvorigin}{40mm}\setlength{\pdfhorigin}{29mm}}{}}

%\def\twoupbook{\twoup\targetlayout{booklet}}

\def\twoupbook{\usepackage[print,twouparticle]{booklet}\special{landscape}%
\target{760}{\paperheight}{\paperwidth}\source{\magstep0}{\paperwidth}{\paperheight}
\ifpdf{\setlength{\pdfpagewidth}{390.8mm}\setlength{\pdfpageheight}{276.3mm}
\setlength{\pdfvorigin}{40mm}\setlength{\pdfhorigin}{29mm}}{}}


% DEFAULTS -------------------------------------------------------------------

% Chapter headings.
%\mychapter{\LARGE \sc \thechapter. #1}{\LARGE \sc #1}
\mychapter{\huge \bf \chapapp\ \thechapter\\[20pt]\Huge\bf #1}{\Huge \bf #1}

% Header
\@ifundefined{signature}% Don't define headings for letter style
{
\pagestyle{threepartheadings}
% Use normal headers as default.
\if@twoside
  \lhead{\rightmark}\rhead{\prepageno\thepage}
  \elhead{\prepageno\thepage}\erhead{\leftmark}
\else
  \lhead{\rightmark}\rhead{\prepageno\thepage}
\fi
}
{
\pagestyle{threepartheadings}
\lhead{\headtoname{}: \ignorespaces\toname\qquad\@date}
\rhead{\pagename{} \prepageno\thepage}
}


% Page size
\a4page
\setlength{\topmargin}{-1cm}
\setlength{\headsep}{1cm}
\setlength{\headheight}{0.5cm}
\setsidemargin{3cm}
\setlength{\parskip}{1.8ex}
\setlength{\marginparwidth}{3.6cm}
\renewcommand{\bottomfraction}{0.2}

% Section heads.
\mysection{section}{\Large\bf}{\thesection~~}
\mysection{subsection}{\large\bf}{\thesubsection~~}
\mysection{subsubsection}{\normalsize\bf}{\thesubsubsection~~}
\mysection{paragraph}{\normalsize\bf}{\theparagraph~}
\mysection{subparagraph}{\normalsize\bf}{\thesubparagraph~}

%\bibliographystyle{hytex}

\def\ifpdf#1#2{\@ifundefined{pdfoutput}{#2}{#1}}

\def\quitesloppy{
\tolerance 1414
\hbadness 1414
\emergencystretch 1.5em
\hfuzz 0.3pt
\widowpenalty=10000
\vfuzz \hfuzz
\raggedbottom}
